import socket
ip = '10.11.146.167'
port = 9999
socket_server = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
socket_server.bind((ip, port))
socket_server.listen(1)
while True:
    conn, addr = socket_server.accept()
    with conn:
        print("connect by", addr)
        try:
            while True:
                data = conn.recv(1024)
                print("客户端:", conn.getpeername(), data.decode())
                if data:
                    # conn.sendall(data)
                    response = input(">>>")
                    conn.sendall(response.encode())
                    print("服务器:", response)
                else:
                    break
        except ConnectionResetError as e:
            print("远程连接断开")
